<%@ page import="com.silverhaze.web.WebConstants" %>
<%@ page import="com.silverhaze.web.data.wot.WoTPlayer" %>
<%@ page import="com.silverhaze.web.data.wot.presentation.WoTPlayerDayStatistics" %>
<%@ page import="com.silverhaze.web.data.wot.presentation.WoTTankStatistics" %>
<%@ page import="com.silverhaze.web.util.DateUtil" %>
<%@ page import="com.silverhaze.web.util.EntityManageUtil" %>
<%@ page import="java.sql.Date" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%

    java.util.Date currentDate = new java.util.Date();
    java.util.Date previousWeekDate = new java.util.Date(currentDate.getTime() - 7 * DateUtil.MSECS_IN_DAY);
    Date previousWeekSQLDate = new Date(currentDate.getTime() - 7 * DateUtil.MSECS_IN_DAY);

    WoTPlayer player = null;
    String playerName = request.getParameter("name");
    List<WoTPlayerDayStatistics> playerDayStatistics = new ArrayList<WoTPlayerDayStatistics>();
    if (playerName != null) {
        List<WoTPlayer> players = EntityManageUtil.load(WoTPlayer.class);

        for (WoTPlayer p : players) {
            if (p.getUser().equals(playerName)) {
                player = p;
                break;
            }
        }

        if (player != null) {
            playerDayStatistics.addAll(EntityManageUtil.loadPlayerStatistics(player, previousWeekSQLDate));
        }
    }
%>

<html>
<head>
    <title>SilverHaze.Info :: World Of Tanks - Статистика <%=player != null ? " - " + player : ""%>
    </title>
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/table.sorter.js"></script>
    <link href="style/style.css" rel="stylesheet">
</head>
<body>
<a href="index.jsp"><img src="img/wot_sml.png" alt="World Of Tanks" border="0"/></a>

<% if (player == null) { %>
<h3>
    Необходимо выбрать активного игрока (<a href="index.jsp">назад</a>).
</h3>
<% } else {%>
<h1><%=player.getUser()%>
</h1>

<% if (playerDayStatistics.size() > 0) { %>

<% for (WoTPlayerDayStatistics dayStatistics : playerDayStatistics) {
%>

<h1>Статистика за <%=WebConstants.DATE_FORMAT.format(dayStatistics.getDate())%>
</h1>

<table>
    <tr>
        <th>Бои</th>
        <th>Побед</th>
        <th>Поражений</th>
        <th>Ничьи</th>
        <th>Опыт</th>
        <th>Нанес повреждений</th>
        <th>Уничтожил</th>
        <th>Обнаружил</th>
        <th>Очки захвата базы</th>
        <th>Очки защиты базы</th>
    </tr>
    <tr>
        <td><%=dayStatistics.getPlayerStatistics().getBattles()%>
        </td>
        <td><%=dayStatistics.getPlayerStatistics().getWins()%> (<%=WebConstants.DOUBLE_FORMAT.format(dayStatistics.getPlayerStatistics().getWinPercent())%>%)
        </td>
        <td><%=dayStatistics.getPlayerStatistics().getLooses()%>  (<%=WebConstants.DOUBLE_FORMAT.format(dayStatistics.getPlayerStatistics().getLoosePercent())%>%)
        </td>
        <td><%=dayStatistics.getPlayerStatistics().getDraws()%>  (<%=WebConstants.DOUBLE_FORMAT.format(dayStatistics.getPlayerStatistics().getDrawPercent())%>%)
        </td>
        <td><%=dayStatistics.getPlayerStatistics().getTotalExp()%>
        </td>
        <td><%=dayStatistics.getPlayerStatistics().getDamagePoints()%>
        </td>
        <td><%=dayStatistics.getPlayerStatistics().getKilled()%>
        </td>
        <td><%=dayStatistics.getPlayerStatistics().getDiscovered()%>
        </td>
        <td><%=dayStatistics.getPlayerStatistics().getBaseAttackPoints()%>
        </td>
        <td><%=dayStatistics.getPlayerStatistics().getBaseDefencePoints()%>
        </td>
    </tr>
</table>

<br>

<h2>Техника</h2>

<table>
    <tr>
        <th>Модель</th>
        <th>Бои</th>
        <th>Побед</th>
    </tr>
    <%
        for (WoTTankStatistics tankStat : dayStatistics.getTankStatistics()) {
            if(tankStat.getTank().contains("M3 Stuart")) {
                continue;
            }
    %>
    <tr>
        <td><%=tankStat.getTankImage() != null ? "<img src=\"" + tankStat.getTankImage() + "\">" : ""%><%=tankStat.getTank()%>
        </td>
        <td><%=tankStat.getBattles()%>
        </td>
        <td><%=tankStat.getWins()%>
        </td>
    </tr>
    <%
        }
    %>
</table>
<%}%>

<% } else {%>

<h2>Стастика для данного игрока отсутствует.</h2>

<% }%>

<div class="copyright">&copy; Иван Бабанин (SilverHaze), 2012 г. <a href="">babanin@gmail.com</a></div>
<% }%>

</body>
</html>